var {
  randomUtils,
  logUtils,
  timeUtils,
  clickUtils,
  clickContent,
} = require ('../../utils/index');
var {App} = require ('../../base/index');
var pointMap = require ('./pointMap');
var inTask = require ('./inTask');
var aShop = require ('./aShop');
var aTreasure = require ('./aTreasure');

var douYinJiSu = new App ('抖音极速版', {
  interval: 10 * 60,
  maxOpenCount: 10,
});

douYinJiSu.runTest = function () {};

douYinJiSu.run = function () {
  this.read ();
  sleep (randomUtils.getRandom (2, 4, 1000));
  clickUtils.clickPointMap (pointMap.首页.赚钱);
  sleep (randomUtils.getRandom (8, 16, 1000));
  if (clickContent ('详情')) {
    sleep (randomUtils.getRandom (2, 4, 1000));
  }
  inTask.init ();
  sleep (randomUtils.getRandom (2, 4, 1000));
  aShop.flow ();
  inTask.init ();
  sleep (randomUtils.getRandom (2, 4, 1000));
  aTreasure.flow ();
  sleep (randomUtils.getRandom (3, 10, 1000));
};

douYinJiSu.read = function () {
  var baseSpan = 30;
  var span = randomUtils.getRandom (baseSpan, baseSpan + 10);
  var startTime = Date.now ();
  var count = 0;
  logUtils.info ('将看视频' + parseInt (span) + '秒');
  while (true) {
    count++;
    sleep (5 * 1000);
    var hasExec = timeUtils.hasExec (startTime);
    if (count % 5 == 0) {
      logUtils.info ('已经看了' + hasExec + '/' + span);
    }
    if (hasExec >= span) {
      if (count % 5 != 0) {
        logUtils.info ('已经看了' + hasExec + '/' + span);
      }
      break;
    }
  }
};
module.exports = douYinJiSu;
